package cn.jhc.Adapter;

import java.util.List;

import com.example.shilehui.ModifyAccountInfoActivity;
import com.example.shilehui.R;
import com.example.shilehui.SelectCityActivity;
import com.example.shilehui.SelectGenderActivity;
import com.example.shilehui.SelectProvincesActivity;

import cn.jhc.Adapter.AssistTopicAdatper.DataWrapper;
import cn.jhc.bean.Province;
import cn.jhc.utils.ActivityForResultRequestCode;
import cn.jhc.utils.Strings;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

public class SelectProvincesAdapter extends BaseAdapter {

	Context context;
	List<Province> provinces;
	private LayoutInflater inflater;
	SelectProvincesActivity selectProvincesActivity;
	public SelectProvincesAdapter(SelectProvincesActivity selectProvincesActivity,
			Context context,
			List<Province> provinces) {
		this.selectProvincesActivity=selectProvincesActivity;
		this.context=context;
		this.provinces=provinces;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);	
	}

	@Override
	public int getCount() {
		return provinces.size();
	}

	@Override
	public Object getItem(int position) {
		return provinces.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	DataWrapper dataWrapper;
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView==null){
			convertView=inflater.inflate(R.layout.select_provinces_listview_item, null);
			TextView province=(TextView) convertView.findViewById(R.id.select_provinces_listview_item_province);
			dataWrapper=new DataWrapper(province);
			convertView.setTag(dataWrapper);
		}else{
			dataWrapper=(DataWrapper) convertView.getTag();
		}
		dataWrapper.province.setText(provinces.get(position).getProvinceName());
		dataWrapper.province.setOnClickListener(new ConvertViewLister(provinces.get(position)));
		return convertView;
	}
	public  final class DataWrapper {
		public  TextView province;


		public DataWrapper(TextView province) {
			this.province=province;

		}
	}
	
	private class ConvertViewLister implements OnClickListener {

		private Province province;
		public ConvertViewLister(Province province) {
			this.province = province;
		}

		@Override
		public void onClick(View v) {
			Intent intent = new Intent(context, SelectCityActivity.class);
			intent.putExtra(Strings.SELECT_PROVINCE,province);
			selectProvincesActivity.startActivityForResult(intent, ActivityForResultRequestCode.SELECT_CITY);
			
		}

	}
}
